package com.milhouz.bomberrokon.events;

import java.util.LinkedList;
import java.util.List;

import com.milhouz.bomberrokon.engines.Engine;

/** Manages events and engines interactions */
public class EventManager {

	/** Events queue */
	private static List<Event> mEventsQueue = new LinkedList<Event>();

	/** Initialize the Event Manager */
	public static void init() {
		mEventsQueue.clear();
	}

	/** Push a new Event in the Event Manager */
	public static void pushEvent(Event event) {
		mEventsQueue.add(event);
	}

	/** Process each event in the queue for each engines then remove the event */
	public static void processEvent(Engine... engines) {
		while (!mEventsQueue.isEmpty()) {
			Event event = mEventsQueue.get(0);
			if (event != null) {
				for (Engine engine : engines) {
					engine.processEvent(mEventsQueue.get(0));
				}
			}
			mEventsQueue.remove(0);
		}
	}
}
